
$(document).ready(function(){
	var id=getvl("id");
  findMachineDetail(id);	
	
});



/**
 * 获取机器详情
 */
function findMachineDetail(id){
	
	   $.ajax({
        type: "GET",
        url: urlcore + "/api/machine/findDetail?id=" + id,
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        data: {},
        success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
            if (data.success == true) {
            	var da=data.data;
            	$("#name").val(da.name);
            	$("#machineCode").val(da.machineCode);
            	$("#address").val(da.address);
            	$("#muserId").val(da.muserId);
            	$("#introducerId").val(da.introducerId);
            	if(da.machineQrCode==null){
            		$("#jiqi").show();
            	}else{
            		var img="<img width=\"120px\" height=\"120px\" src=\"" + da.machineQrCode + "\">";
            		$("#machineQrCode").html(img);
            	}
            	
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            alert("删除失败");
        }
    });
	
}


/**
 * 生成机器二维码
 */

function generateMachineQrCode(){
	var id=getvl("id");
	var muserId=$("#muserId").val();
	var introducerId=$("#introducerId").val();
	var machineCode=$("#machineCode").val();
	if(muserId==""){
		alert("会员ID不能为空");
		return;
	}
	   $.ajax({
        type: "GET",
        url: urlcore + "/api/machine/generateMachineQrCode?machineCode=" + machineCode+"&id="+id,
        dataType: "json",
        headers: {"Content-Type": "application/json;charset=UTF-8"},
        data: {},
        success: function (data) {//data是返回的hash,key之类的值，key是定义的文件名
            if (data.success == true) {
            	alert(data.msg);
          
            } else {
                alert(data.msg);
            }
        },
        error: function () {
            alert("生成二维码失败");
        }
    });
    

	
}


/**
 * 修改
 */
function revise(){
	var id=getvl("id");
    var flag = $('#formMsg').valid();
	var formData = $("#formMsg").serializeJSON(); 
	formData.id=id;
	if(flag){
			$.ajax({
			url: urlcore + "/api/machine/update",
			type: "post",
			dataType: 'json',
			contentType: "application/json;charset=utf-8",
			data: JSON.stringify(formData),
			processData: false,
			success:function(data){
				if(data.success == true){
					alert("修改成功")
					location.href="machine_list.html";
				}else{
					alert(data.msg);
				}
			},
			error:function() {
				/*alert("error");*/
			}
		});
		
	}
	
}
